package pl.smath.regex.tree.vertexes;

import pl.smath.regex.exceptions.ParseError;

public class ConstVertex extends Vertex implements Comparable<ConstVertex> {

	private String constant = "";
	
	public ConstVertex(String parse) throws ParseError {
		if (parse.matches("-?[0-9]+"))
			constant = parse;
		else if (parse.equalsIgnoreCase("infinity"))
			constant = "INF";
		else 
			throw new ParseError("Constant contains no-digit char.");
	}
	
	public ConstVertex(Integer i) {
		constant = i.toString();
	}

	public String serialize() {
		return "CONST[" + constant + "]";
	}
	
	public String getConstant() {
		return constant;
	}

	@Override
	public int compareTo(ConstVertex o) {
		if (o.getConstant().equals("INF")) return -1;
		int p = Integer.parseInt(o.getConstant());
		int l = Integer.parseInt(constant);
		return l-p;
	}
	
}
